package iscript.gameFramework.GameLite.content 
{
	import flash.utils.Dictionary;
	import flash.utils.getQualifiedClassName;
	import iscript.gameFramework.GameLite.core.GameModel;
	import iscript.gameFramework.GameLite.events.GameContentEvent;

	internal class GameModelContent implements IGameContent
	{
		private var _data:Dictionary = new Dictionary();
		private var _gameContent:GameContent
		
		public function GameModelContent(gameContent:GameContent) 
		{
			_gameContent = gameContent;
		}
		
		//public function get KEY():Array { return _data.getAllKeys() }	
		
		public function add(model:GameModel):void
		{
			var key:String =  getQualifiedClassName(model).split( "::" ).join( "." );
		    if (_data[key]==null){
				  _data[key] = model;
			      var event:GameContentEvent = new GameContentEvent(GameContentEvent.ADDMODEL);
				       event.key = key;
					   event.content = model;
					   _gameContent.dispatchEvent(event);
				
				   var e:GameContentEvent = new GameContentEvent(GameContentEvent.EVERYTHING)
					   e.key = key;
					   e.content = model;
					   _gameContent.dispatchEvent(e);	   
				}
		}
		

		
		public function get(key:*):GameModel
		{
			return _data[key]
		}
		
		public function contain(key:*):Boolean {
			  return  _data[key] != null;
		}
		
		public function remove(key:*):void
		{
			delete  _data[key];
		}
		
			
	}

}